package com.skirmisher.inspection.conform.controller;

import com.skirmisher.inspection.common.utils.PageUtils;
import com.skirmisher.inspection.conform.entity.InsConformTempQueryEntity;
import com.skirmisher.inspection.conform.entity.InsConformTemplate;
import com.skirmisher.inspection.conform.entity.InsConformTemplateSave;
import com.skirmisher.inspection.conform.service.InsConformTemplateService;
import com.skirmisher.inspection.inspection.testController.ResponseModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName InsConformTemplateController
 * @Description TODO
 * @Author hanwangxin
 * @Date 2020/12/16 下午10:31
 * @Version 1.0
 */
@Api(tags = "符合巡查模板接口")
@RestController
@RequestMapping("/conform")
public class InsConformTemplateController {

    @Autowired
    private InsConformTemplateService insConformTemplateService;

    @ApiOperation(value = "保存符合巡查模板")
    //@ApiOperationSupport(ignoreParameters = {"name"})
    @PostMapping(value = "/saveConformTemp")
    public ResponseModel saveConformTemp(@RequestBody @Validated InsConformTemplateSave tempSave){

        ResponseModel responseModel = new ResponseModel();

        insConformTemplateService.saveConformTemp(tempSave,responseModel);
        return  responseModel;
    }

    @ApiOperation(value = "获取符合巡查模板详情")
    @ApiImplicitParam(name = "tempId",value = "模板id",required = true)
    @GetMapping(value = "/getTempDetail")
    public ResponseModel getTempDetail(String tempId){
        ResponseModel responseModel = new ResponseModel();
        if (StringUtils.isEmpty(tempId)){
            responseModel.setCode(201);
            responseModel.setMessage("无模板id");
            return responseModel;
        }
        InsConformTemplate insConformTemplate = insConformTemplateService.getTempDetail(tempId);
        responseModel.setData(insConformTemplate);
        return  responseModel;
    }
    @ApiOperation(value = "符合巡查模板页面查询")
    @GetMapping(value = "/getTempPageData")
    public ResponseModel getTempPageData(InsConformTempQueryEntity query){

        ResponseModel responseModel = new ResponseModel();
        //参数校验
        Integer startRow = PageUtils.getStartRow(query.getPage(), query.getRows());
        if (startRow == null || startRow < 0){
            responseModel.setCode(201);
            responseModel.setMessage("分页参数有误");
            return  responseModel;
        }
        query.setStartRows(startRow);
        insConformTemplateService.getTempPageData(query);
        responseModel.setDataDataGrid(query.getDateList(), query.getCount());


        return responseModel;
    }


    /**
     * @Author hanwangxin
     * @Description //TODO 批量删除巡检模板 * @Date 下午9:55 2020/12/12
     * @Param [tempIds]
     * @return com.skirmisher.inspection.inspection.testController.ResponseModel
     **/
    @ApiOperation(value = "批量删除模板")
    @ApiImplicitParam(name = "tempIds",value = "模板id集合",required = true)
    @PostMapping(value = "/deletDaliyTemp")
    public ResponseModel deletDaliyTemp(@RequestBody List<String> tempIds){
        ResponseModel responseModel = new ResponseModel();
        insConformTemplateService.deletConformTemp(tempIds);
        return responseModel;
    }

    @ApiOperation(value = "更新巡查模板")
    //@ApiOperationSupport(ignoreParameters = {"name"})
    @PostMapping(value = "/updateConformTemp")
    public ResponseModel updateConformTemp(@RequestBody @Validated InsConformTemplateSave tempSave){

        ResponseModel responseModel = new ResponseModel();

        String id = tempSave.getId();
        if (StringUtils.isEmpty(id)){
            responseModel.setCode(201);
            responseModel.setMessage("无模板id");
            return responseModel;
        }

        insConformTemplateService.updateConformTemp(tempSave,responseModel);
        return  responseModel;

    }

    /**
     * @Author hanwangxin
     * @Description //TODO 批量启用巡查模板 * @Date 下午9:55 2020/12/12
     * @Param [tempIds]
     * @return com.skirmisher.inspection.inspection.testController.ResponseModel
     **/
    @ApiOperation(value = "批量启用符合巡查模板")
    @ApiImplicitParam(name = "tempIds",value = "模板id集合",required = true)
    @PostMapping(value = "/startConformTemp")
    public ResponseModel startConformTemp(@RequestBody List<String> tempIds){
        ResponseModel responseModel = new ResponseModel();
        insConformTemplateService.startConformTemp(tempIds);
        return responseModel;
    }
}
